/**
 * 对一个存放字符串的双向链表，把存放在其中的字符串转化为大写字母
 */

#include <stdio.h>
#include <string.h>
#include "list.h"

#define MAX 50

typedef struct str_list {
	char str[MAX];
	struct list_head list;
} Str_list;

Str_list str_list[MAX];
LIST_HEAD(head);

static int input_string(void) 
{
	int i = 0;
	printf("please input the strings(end by 0)\n");
	while (1) {
		scanf("%s", str_list[i].str);
		if ('0' == str_list[i].str[0]) {
			return i+1;
		}
		list_add_tail(&str_list[i].list, &head);
		i++;
	}
}

void output_string(void)
{
	struct list_head *pos = NULL;
	Str_list *tmp = NULL;
	list_for_each(pos, &head) {
		tmp = (Str_list *)list_entry(pos, Str_list, list);
		printf("%s\n", tmp->str);
	}
}

int trans(void)
{
	int i = 0;
	char *p = NULL;
	struct list_head *pos = NULL;
	Str_list *tmp = NULL;
	list_for_each(pos, &head) {
		tmp = (Str_list *)list_entry(pos, Str_list, list);
		p = tmp->str;
		while (*p != '\0') {
			if (*p <= 'z' && *p >= 'a') {
				*p = *p - ('a' - 'A');
			}
			p++;
		}
	}
	return 0;
}

int main(int argc, char **argv)
{
	if (0 > input_string()) {
		printf("E: input\n");
		return -1;
	}

	trans();

	output_string();
	return 0;
}
